package study.saas.web.portal.sys.admin;


import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import study.saas.common.viewmodel.ApiResultV2;
import study.saas.order.entity.Commodity;
import study.saas.order.entity.Orders;
import study.saas.order.service.OrdersFacade;
import study.saas.order.service.model.OrdersMakeDTO;
import study.saas.order.service.model.OrdersSearchDTO;

/**
 * @author zxx
 */

@Api(tags = "订单管理")
@RestController
@RequestMapping(value = "sys/order")
public class OrdersController {
    @Reference(version = "1.0.0")
    private OrdersFacade ordersFacade;

    @ApiOperation(value = "下单")
    @RequestMapping(value = "/make",method = RequestMethod.POST)
    public ApiResultV2<Orders> make(OrdersMakeDTO make) {
        if(make == null) {
            return ApiResultV2.error("数据不能为空");
        }
        return ordersFacade.make(make);
    }

    @ApiOperation(value = "订单查询(用户名）")
    @RequestMapping(value = "/getByUserName",method = RequestMethod.GET)
    public ApiResultV2<Orders> getByUserName(String userName) {
        if(userName==null) {
            return ApiResultV2.error("数据不能为空！");
        }
        return ordersFacade.getByUserName(userName);
    }

    @ApiOperation(value = "订单查询(商品名）")
    @RequestMapping(value = "/getByCommodityName",method = RequestMethod.GET)
    public ApiResultV2<Orders> getByCommodityName(String commodityName) {
        if(commodityName==null) {
            return ApiResultV2.error("数据不能为空！");
        }
        return ordersFacade.getByCommodityName(commodityName);
    }

    @ApiOperation(value = "订单查询(商品名和用户名）")
    @RequestMapping(value = "/search",method = RequestMethod.GET)
    public ApiResultV2<Orders> search(OrdersSearchDTO search) {
        if(search==null) {
            return ApiResultV2.error("数据不能为空！");
        }
        return ordersFacade.search(search);
    }
}
